package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;


import com.woyowodaows.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/4.
 */

public class YNDialog extends Dialog {


    @BindView(R.id.tv_dialog_msg)
    TextView tvMessage;
    @BindView(R.id.bt_dialog_cancel)
    TextView tvCancel;
    @BindView(R.id.bt_dialog_sure)
    TextView tvSure;

    private Context context;
    private String title;
    private OnDialogListener dialogListener;


    public YNDialog(@NonNull Context context) {
        super(context, R.style.MyDialogStyle);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_yes_no, null);
        setContentView(view);
        ButterKnife.bind(this, view);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dialogListener != null) {
                    dialogListener.onCancelClick(view);
                }
                dismiss();
            }
        });
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (dialogListener != null) {
                    dialogListener.onSureClick(view);
                }
                dismiss();
            }
        });
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics();
        lp.width = (int) (d.widthPixels * 0.8);
        dialogWindow.setAttributes(lp);


    }


    public void setTitleText(String title) {
        if (title != null) {
            tvMessage.setText(title);
        }
    }

    public void setMessageText(String title){
        if (title != null) {
            tvMessage.setText(title);
        }
    }

    public void goneCancelButon(){
        tvCancel.setVisibility(View.GONE);
    }

    public void setSureText(String text) {
        if (text != null){
            tvSure.setText(text);
        }
    }

    public void setCancelText(String text) {
        if (text != null){
            tvCancel.setText(text);
        }
    }

    public void setDialogListener(OnDialogListener dialogListener) {
        this.dialogListener = dialogListener;
    }

    public interface OnDialogListener {
        void onCancelClick(View view);

        void onSureClick(View view);
    }


}
